<?php 
include_once 'site_config.php';
include_once "ra_global.php";
if(!$_GET['code']){
	echo "<script language=javascript>location.href='https://open.weixin.qq.com/connect/oauth2/authorize?appid=".APPID."&redirect_uri=".urlencode(SiteUrl.'cheap_code.php')."&response_type=code&scope=snsapi_base&state=1#wechat_redirect';</script>";
}

//获取code
$getcode=getToken("https://api.weixin.qq.com/sns/oauth2/access_token?appid=".APPID."&secret=".APPSECRET."&code=".$_GET['code']."&grant_type=authorization_code");
$user_obj=json_decode($getcode);
if(!$user_obj->openid){
	echo "<script language=javascript>window.location.href='https://open.weixin.qq.com/connect/oauth2/authorize?appid=".APPID."&redirect_uri=".urlencode(SiteUrl.'cheap_code.php')."&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect';</script>";
}
function getToken($url){
	$ch = curl_init(); 
	curl_setopt($ch, CURLOPT_URL,$url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
	$row=curl_exec($ch); 
	return $row;
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width,target-densitydpi=high-dpi,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<link href="images/m.css" rel="stylesheet" type="text/css" />
<script src="inc/jquery.min.js" type="text/javascript"></script>
<title>喜力超凡大师 滚雪球卡券验证</title>
</head>

<body>
<script language="javascript">
function onBridgeReady(){
	WeixinJSBridge.call('hideOptionMenu');
}

if (typeof WeixinJSBridge == "undefined"){
	if( document.addEventListener ){
		document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
	}else if (document.attachEvent){
	document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
	document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
	}
}else{
	onBridgeReady();
}
</script>
<div class="container">
	<div class="p8">
		<img class="p8bg bg" src="images/p8bg.jpg">
		<img id="p8_1" src="images/p8_1.jpg" style="position:absolute">
		<input id="openid" type="hidden" name="openid" value="<?php echo $user_obj->openid;?>">
		<input class="ipt" id="p8text" type="text" name="cheap_code" value="">
        <div id="p8bar">
        	<img class="bg" src="images/p8barbg.png">
            <img class="p8bt txt" src="images/p8bt.jpg">		
        </div>
        <div id="p8box">
        	<img class="bg" src="images/p8boxbg.png">
            <img class="p8bt txt" src="images/p8bt.jpg">		
        </div>
	</div>
</div>
<script type="text/javascript">
var x,y,p;
$(document).ready(function() {
	x=parseInt(window.innerWidth);
	y=parseInt(window.innerHeight);
	p=720/x;
	getWidth();
	
	$('.p8bt').click(function(){
		location.href='cheap_code.php';
	});
});	

$('#p8_1').click(function(){
	var openid=$('#openid').val();
	var cheap_code=$('#p8text').val();
	$.ajax({
		type: "GET",
		url: "ra_ajax.php?ra_cheap_code=1&cheap_code="+cheap_code+"&openid="+openid,
		success: function(data){
			if(data == 'success'){
				$('#p8bar').fadeIn(500);
			}else{
				$('#p8box').fadeIn(500);
			}
		}
	});
});

function getWidth(){
	$('.p8,.container,.bg,#p8bar,#p8box').width(x);
	$('.p1,.p2,.p3,.p4,.p5,.p6,.p7,.p8,#p8bar,#p8box').css({left:0,top:0});
	//p8
	$('.p8bg,.p8').css({left:0,top:0});
	$('#p8_1').width(131/p).height(76/p).css({left:(x-131/p)/2+'px',top:494/p+'px'});
	$('#p8text').css({left:89/p+'px',top:319/p+'px',width:546/p+'px',height:120/p+'px',fontSize:35/p+'px'});
	$('.p8bt').width(134/p).height(76/p).css({left:(x-134/p)/2+'px',top:624/p+'px'});
}
</script>
</body>
</html>